package com.scs.application.config;

import com.scs.application.modules.thirdparty.response.controller.HisWSJsonController;
import com.scs.application.modules.thirdparty.soap.SOAPHIS;
import com.scs.application.modules.thirdparty.soap.SOAPMock;
import org.apache.cxf.Bus;
import org.apache.cxf.bus.spring.SpringBus;
import org.apache.cxf.jaxws.EndpointImpl;
import org.apache.cxf.transport.servlet.CXFServlet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;

import javax.xml.ws.Endpoint;
/**
 * @Description：CXF配置
 */
@Configuration
public class CxfConfig {
    @Autowired
    @Lazy
    CxfAuthInterceptor cxfAuthInterceptor;

    @Autowired
    @Lazy
    private SOAPHIS soapHIS;

    @Autowired
    @Lazy
    private SOAPMock soapHISMock;

    @Autowired
    @Lazy
    private HisWSJsonController hisWSJsonController;

    @Bean(name = "cxfServlet")
    public ServletRegistrationBean cxfServlet() {
        return new ServletRegistrationBean(new CXFServlet(), "/webservice/*");
    }

    @Bean(name = Bus.DEFAULT_BUS_ID)
    public SpringBus springBus() {
        return new SpringBus();
    }


  /**
    * @Description： SPD提供给HIS的真实接口
    */
    @Bean(name = "soapHISEndpoint")
    public Endpoint soapHISEndpoint() {
        EndpointImpl endpoint = new EndpointImpl(springBus(), soapHIS);
        endpoint.publish("/soapHis");
        endpoint.getInInterceptors().add(cxfAuthInterceptor);//添加校验拦截器
        return endpoint;
    }

  /**
    * @Description： his提供给SPD系统，本地化的模拟接口
    */
    @Bean(name = "soapHISMockEndpoint")
    public Endpoint soapHISMockEndpoint() {
        EndpointImpl endpoint = new EndpointImpl(springBus(), soapHISMock);
        endpoint.publish("/soapHISMock");
        endpoint.getInInterceptors().add(cxfAuthInterceptor);//添加校验拦截器
        return endpoint;
    }

    /**
     * @Description： his调用SPD接口 JSON
     */
    @Bean(name = "WebServiceJsonHIS")
    public Endpoint WebServiceJsonHisEndpoint() {
        EndpointImpl endpoint = new EndpointImpl(springBus(), hisWSJsonController);
        endpoint.publish("/WSJsonHis");
        endpoint.getInInterceptors().add(cxfAuthInterceptor);//添加校验拦截器
        return endpoint;
    }

}

